package com.example.common.utils;

import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.SneakyThrows;

import java.util.List;

/**
 * <p>
 *
 * </p>
 *
 * @author zyred
 * @since v 0.1
 **/
public class JacksonUtils {

    @SneakyThrows
    public static <T> T json2List(String json, TypeReference<T> re) {
        return new ObjectMapper().readValue(json, re);
    }

    @SneakyThrows
    public static <T> T json2List (Object obj, TypeReference<T> re) {
        return new ObjectMapper().readValue(new ObjectMapper().writeValueAsString(obj), re);
    }
}
